﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml;

namespace DrawingScreen.Objects
{
    public class CClipArt : CDrawingObject
    {
        public Rectangle Rect = new Rectangle(-100,-100, 10, 10);

        private Bitmap bmp;

        private int id = -1;

        public CClipArt(int id)
        {
            this.id = id;

            switch (id)
            {
                case 0:
                    bmp = Properties.Resources.ca00;
                    break;
                case 1:
                    bmp = Properties.Resources.ca01;
                    break;
                case 2:
                    bmp = Properties.Resources.ca02;
                    break;
                case 3:
                    bmp = Properties.Resources.ca03;
                    break;
                case 4:
                    bmp = Properties.Resources.ca04;
                    break;
                case 5:
                    bmp = Properties.Resources.ca05;
                    break;
                case 6:
                    bmp = Properties.Resources.ca06;
                    break;
                case 7:
                    bmp = Properties.Resources.ca07;
                    break;
                case 8:
                    bmp = Properties.Resources.ca08;
                    break;
                case 9:
                    bmp = Properties.Resources.ca09;
                    break;
                case 10:
                    bmp = Properties.Resources.ca10;
                    break;
                case 11:
                    bmp = Properties.Resources.ca11;
                    break;
                case 12:
                    bmp = Properties.Resources.ca12;
                    break;
                case 13:
                    bmp = Properties.Resources.ca13;
                    break;
                case 14:
                    bmp = Properties.Resources.ca14;
                    break;
            }
        }

        public override void Draw(System.Drawing.Graphics g)
        {
            g.DrawImage(this.bmp, this.Rect);
        }

        public override XmlNode convertToXmlNode(XmlDocument doc)
        {
            try
            {
                XmlElement eleObject = doc.CreateElement("OBJECT");

                XmlAttribute attObjectID = doc.CreateAttribute("id");
                attObjectID.Value = CDrawingObject.CLIPART_ID.ToString();
                eleObject.Attributes.Append(attObjectID);

                //////////////////////////////////////////////////////////////
                XmlElement eleClipArt = doc.CreateElement("CLIPART");

                XmlAttribute attID = doc.CreateAttribute("id");
                attID.Value = id.ToString();
                eleClipArt.Attributes.Append(attID);

                XmlElement eleRECT = Global.CreateXmlElementFromRectangle(doc, Rect);
                eleClipArt.AppendChild(eleRECT);

                //////////////////////////////////////////////////////////////

                eleObject.AppendChild(eleClipArt);

                return eleObject;
            }
            catch
            {
                return null;
            }
        }

        public static CClipArt CreateDrawingObject(XmlElement eleObject)
        {
            try
            {
                XmlElement eleClipArt = (XmlElement)eleObject.FirstChild;

                int id = Int32.Parse(eleClipArt.Attributes["id"].Value);

                CClipArt clipArt = new CClipArt(id);

                Rectangle rect = Global.CreateRectangleFormXmlElement((XmlElement)eleClipArt.FirstChild);

                clipArt.Rect = rect;

                return clipArt;

            }
            catch(Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                return null;
               
                
            }
        }
    }
}
